<?php

namespace GotchaDatabase\om;

use \Criteria;
use \Exception;
use \ModelCriteria;
use \PDO;
use \Propel;
use \PropelException;
use \PropelObjectCollection;
use \PropelPDO;
use GotchaDatabase\JasminumNewsletters;
use GotchaDatabase\JasminumNewslettersPeer;
use GotchaDatabase\JasminumNewslettersQuery;

/**
 * Base class that represents a query for the 'Jasminum_Newsletters' table.
 *
 *
 *
 * @method JasminumNewslettersQuery orderById($order = Criteria::ASC) Order by the Id column
 * @method JasminumNewslettersQuery orderByTitle($order = Criteria::ASC) Order by the Title column
 * @method JasminumNewslettersQuery orderByBody($order = Criteria::ASC) Order by the Body column
 * @method JasminumNewslettersQuery orderByCreationDate($order = Criteria::ASC) Order by the Creation_Date column
 * @method JasminumNewslettersQuery orderByCreationTime($order = Criteria::ASC) Order by the Creation_Time column
 * @method JasminumNewslettersQuery orderBySendDate($order = Criteria::ASC) Order by the Send_Date column
 * @method JasminumNewslettersQuery orderBySendTime($order = Criteria::ASC) Order by the Send_Time column
 * @method JasminumNewslettersQuery orderByIsSend($order = Criteria::ASC) Order by the Is_Send column
 *
 * @method JasminumNewslettersQuery groupById() Group by the Id column
 * @method JasminumNewslettersQuery groupByTitle() Group by the Title column
 * @method JasminumNewslettersQuery groupByBody() Group by the Body column
 * @method JasminumNewslettersQuery groupByCreationDate() Group by the Creation_Date column
 * @method JasminumNewslettersQuery groupByCreationTime() Group by the Creation_Time column
 * @method JasminumNewslettersQuery groupBySendDate() Group by the Send_Date column
 * @method JasminumNewslettersQuery groupBySendTime() Group by the Send_Time column
 * @method JasminumNewslettersQuery groupByIsSend() Group by the Is_Send column
 *
 * @method JasminumNewslettersQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method JasminumNewslettersQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method JasminumNewslettersQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method JasminumNewsletters findOne(PropelPDO $con = null) Return the first JasminumNewsletters matching the query
 * @method JasminumNewsletters findOneOrCreate(PropelPDO $con = null) Return the first JasminumNewsletters matching the query, or a new JasminumNewsletters object populated from the query conditions when no match is found
 *
 * @method JasminumNewsletters findOneByTitle(string $Title) Return the first JasminumNewsletters filtered by the Title column
 * @method JasminumNewsletters findOneByBody(string $Body) Return the first JasminumNewsletters filtered by the Body column
 * @method JasminumNewsletters findOneByCreationDate(string $Creation_Date) Return the first JasminumNewsletters filtered by the Creation_Date column
 * @method JasminumNewsletters findOneByCreationTime(string $Creation_Time) Return the first JasminumNewsletters filtered by the Creation_Time column
 * @method JasminumNewsletters findOneBySendDate(string $Send_Date) Return the first JasminumNewsletters filtered by the Send_Date column
 * @method JasminumNewsletters findOneBySendTime(string $Send_Time) Return the first JasminumNewsletters filtered by the Send_Time column
 * @method JasminumNewsletters findOneByIsSend(boolean $Is_Send) Return the first JasminumNewsletters filtered by the Is_Send column
 *
 * @method array findById(int $Id) Return JasminumNewsletters objects filtered by the Id column
 * @method array findByTitle(string $Title) Return JasminumNewsletters objects filtered by the Title column
 * @method array findByBody(string $Body) Return JasminumNewsletters objects filtered by the Body column
 * @method array findByCreationDate(string $Creation_Date) Return JasminumNewsletters objects filtered by the Creation_Date column
 * @method array findByCreationTime(string $Creation_Time) Return JasminumNewsletters objects filtered by the Creation_Time column
 * @method array findBySendDate(string $Send_Date) Return JasminumNewsletters objects filtered by the Send_Date column
 * @method array findBySendTime(string $Send_Time) Return JasminumNewsletters objects filtered by the Send_Time column
 * @method array findByIsSend(boolean $Is_Send) Return JasminumNewsletters objects filtered by the Is_Send column
 *
 * @package    propel.generator.gotcha.om
 */
abstract class BaseJasminumNewslettersQuery extends ModelCriteria
{
    /**
     * Initializes internal state of BaseJasminumNewslettersQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'codenova_jasminum', $modelName = 'GotchaDatabase\\JasminumNewsletters', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new JasminumNewslettersQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param   JasminumNewslettersQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return JasminumNewslettersQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof JasminumNewslettersQuery) {
            return $criteria;
        }
        $query = new JasminumNewslettersQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return   JasminumNewsletters|JasminumNewsletters[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = JasminumNewslettersPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is already in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(JasminumNewslettersPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Alias of findPk to use instance pooling
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return                 JasminumNewsletters A model object, or null if the key is not found
     * @throws PropelException
     */
     public function findOneById($key, $con = null)
     {
        return $this->findPk($key, $con);
     }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return                 JasminumNewsletters A model object, or null if the key is not found
     * @throws PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT `Id`, `Title`, `Body`, `Creation_Date`, `Creation_Time`, `Send_Date`, `Send_Time`, `Is_Send` FROM `Jasminum_Newsletters` WHERE `Id` = :p0';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new JasminumNewsletters();
            $obj->hydrate($row);
            JasminumNewslettersPeer::addInstanceToPool($obj, (string) $key);
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return JasminumNewsletters|JasminumNewsletters[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(12, 56, 832), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|JasminumNewsletters[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {

        return $this->addUsingAlias(JasminumNewslettersPeer::ID, $key, Criteria::EQUAL);
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {

        return $this->addUsingAlias(JasminumNewslettersPeer::ID, $keys, Criteria::IN);
    }

    /**
     * Filter the query on the Id column
     *
     * Example usage:
     * <code>
     * $query->filterById(1234); // WHERE Id = 1234
     * $query->filterById(array(12, 34)); // WHERE Id IN (12, 34)
     * $query->filterById(array('min' => 12)); // WHERE Id >= 12
     * $query->filterById(array('max' => 12)); // WHERE Id <= 12
     * </code>
     *
     * @param     mixed $id The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterById($id = null, $comparison = null)
    {
        if (is_array($id)) {
            $useMinMax = false;
            if (isset($id['min'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::ID, $id['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($id['max'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::ID, $id['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::ID, $id, $comparison);
    }

    /**
     * Filter the query on the Title column
     *
     * Example usage:
     * <code>
     * $query->filterByTitle('fooValue');   // WHERE Title = 'fooValue'
     * $query->filterByTitle('%fooValue%'); // WHERE Title LIKE '%fooValue%'
     * </code>
     *
     * @param     string $title The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByTitle($title = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($title)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $title)) {
                $title = str_replace('*', '%', $title);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::TITLE, $title, $comparison);
    }

    /**
     * Filter the query on the Body column
     *
     * Example usage:
     * <code>
     * $query->filterByBody('fooValue');   // WHERE Body = 'fooValue'
     * $query->filterByBody('%fooValue%'); // WHERE Body LIKE '%fooValue%'
     * </code>
     *
     * @param     string $body The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByBody($body = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($body)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $body)) {
                $body = str_replace('*', '%', $body);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::BODY, $body, $comparison);
    }

    /**
     * Filter the query on the Creation_Date column
     *
     * Example usage:
     * <code>
     * $query->filterByCreationDate('2011-03-14'); // WHERE Creation_Date = '2011-03-14'
     * $query->filterByCreationDate('now'); // WHERE Creation_Date = '2011-03-14'
     * $query->filterByCreationDate(array('max' => 'yesterday')); // WHERE Creation_Date > '2011-03-13'
     * </code>
     *
     * @param     mixed $creationDate The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByCreationDate($creationDate = null, $comparison = null)
    {
        if (is_array($creationDate)) {
            $useMinMax = false;
            if (isset($creationDate['min'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::CREATION_DATE, $creationDate['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($creationDate['max'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::CREATION_DATE, $creationDate['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::CREATION_DATE, $creationDate, $comparison);
    }

    /**
     * Filter the query on the Creation_Time column
     *
     * Example usage:
     * <code>
     * $query->filterByCreationTime('2011-03-14'); // WHERE Creation_Time = '2011-03-14'
     * $query->filterByCreationTime('now'); // WHERE Creation_Time = '2011-03-14'
     * $query->filterByCreationTime(array('max' => 'yesterday')); // WHERE Creation_Time > '2011-03-13'
     * </code>
     *
     * @param     mixed $creationTime The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByCreationTime($creationTime = null, $comparison = null)
    {
        if (is_array($creationTime)) {
            $useMinMax = false;
            if (isset($creationTime['min'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::CREATION_TIME, $creationTime['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($creationTime['max'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::CREATION_TIME, $creationTime['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::CREATION_TIME, $creationTime, $comparison);
    }

    /**
     * Filter the query on the Send_Date column
     *
     * Example usage:
     * <code>
     * $query->filterBySendDate('2011-03-14'); // WHERE Send_Date = '2011-03-14'
     * $query->filterBySendDate('now'); // WHERE Send_Date = '2011-03-14'
     * $query->filterBySendDate(array('max' => 'yesterday')); // WHERE Send_Date > '2011-03-13'
     * </code>
     *
     * @param     mixed $sendDate The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterBySendDate($sendDate = null, $comparison = null)
    {
        if (is_array($sendDate)) {
            $useMinMax = false;
            if (isset($sendDate['min'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::SEND_DATE, $sendDate['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($sendDate['max'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::SEND_DATE, $sendDate['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::SEND_DATE, $sendDate, $comparison);
    }

    /**
     * Filter the query on the Send_Time column
     *
     * Example usage:
     * <code>
     * $query->filterBySendTime('2011-03-14'); // WHERE Send_Time = '2011-03-14'
     * $query->filterBySendTime('now'); // WHERE Send_Time = '2011-03-14'
     * $query->filterBySendTime(array('max' => 'yesterday')); // WHERE Send_Time > '2011-03-13'
     * </code>
     *
     * @param     mixed $sendTime The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterBySendTime($sendTime = null, $comparison = null)
    {
        if (is_array($sendTime)) {
            $useMinMax = false;
            if (isset($sendTime['min'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::SEND_TIME, $sendTime['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($sendTime['max'])) {
                $this->addUsingAlias(JasminumNewslettersPeer::SEND_TIME, $sendTime['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::SEND_TIME, $sendTime, $comparison);
    }

    /**
     * Filter the query on the Is_Send column
     *
     * Example usage:
     * <code>
     * $query->filterByIsSend(true); // WHERE Is_Send = true
     * $query->filterByIsSend('yes'); // WHERE Is_Send = true
     * </code>
     *
     * @param     boolean|string $isSend The value to use as filter.
     *              Non-boolean arguments are converted using the following rules:
     *                * 1, '1', 'true',  'on',  and 'yes' are converted to boolean true
     *                * 0, '0', 'false', 'off', and 'no'  are converted to boolean false
     *              Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function filterByIsSend($isSend = null, $comparison = null)
    {
        if (is_string($isSend)) {
            $isSend = in_array(strtolower($isSend), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
        }

        return $this->addUsingAlias(JasminumNewslettersPeer::IS_SEND, $isSend, $comparison);
    }

    /**
     * Exclude object from result
     *
     * @param   JasminumNewsletters $jasminumNewsletters Object to remove from the list of results
     *
     * @return JasminumNewslettersQuery The current query, for fluid interface
     */
    public function prune($jasminumNewsletters = null)
    {
        if ($jasminumNewsletters) {
            $this->addUsingAlias(JasminumNewslettersPeer::ID, $jasminumNewsletters->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }

}
